#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>

using namespace std;

class Solution {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    int n, m;
    void dfs(vector<vector<int>>& visted, vector<vector<char>>& grid, int x, int y)
    {
        visted[x][y] = 1;
        for (int i = 0; i < 4; i++)
        {
            int xi = dx[i] + x;
            int yi = dy[i] + y;
            if (xi >= 0 && yi >= 0 && xi < n && yi < m && grid[xi][yi] == '1' && visted[xi][yi] == 0) dfs(visted, grid, xi, yi);
        }
    }
    int numIslands(vector<vector<char>>& grid) {
        int sum = 0;
        n = grid.size();
        m = grid[0].size();
        vector<vector<int>> visted(n, vector<int>(m, 0));
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (grid[i][j] == '1' && visted[i][j] == 0)
                {
                    dfs(visted, grid, i, j);
                    sum++;
                }
            }
        }
        return sum;
    }
};

int main() {
    return 0;
}